package cn.cnhis.online.activity.forgotpassword.view;

import android.content.Context;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;

import androidx.annotation.Nullable;
import butterknife.BindView;
import cn.cnhis.online.R;
import cn.cnhis.online.activity.forgotpassword.contract.IForgotPasswordContract;
import cn.cnhis.online.activity.forgotpassword.presenter.ForgotPasswordPresenter;
import cn.cnhis.online.activity.login.view.LoginActivity;
import cn.cnhis.online.activity.main.view.MainActivity;
import cn.cnhis.online.base.ActivityStack;
import cn.cnhis.online.base.BaseMvpActivity;
import cn.cnhis.online.mymodule.Api;
import cn.cnhis.online.mymodule.Utils.PackageUtil;
import cn.cnhis.online.mymodule.sp.MySpUtils;

/**
 * @author 刘祥龙
 * @describe
 * @date 2020/2/29  17:36
 * - generate by MvpAutoCodePlus plugin.
 */

public class ForgotPasswordActivity extends BaseMvpActivity<IForgotPasswordContract.View, IForgotPasswordContract.Presenter> implements IForgotPasswordContract.View {

//    private static final String TEST_URL_web = "http://cnhis.f3322.org:10080/dev_crmweb/h5/#/forgetpassword";

    @BindView(R.id.webview)
    WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityStack.getInstance().pushActivity(this);
        setContentView(R.layout.activity_forgotpassword);
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        setThemeolor();
        initWebview();
    }

    private void initWebview() {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setDatabaseEnabled(true);
//        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setAppCacheEnabled(true);
//        webView.getSettings().setCacheMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.getSettings().setLoadWithOverviewMode(true);
//        webView.loadUrl(URL_web);
        webView.addJavascriptInterface(new JavaScriptinterface(this),
                "Android");
        setWebViewMargin(webView);
        webView.loadUrl(Api.FORGETPASSWORD);
    }

    public class JavaScriptinterface {
        Context context;

        public JavaScriptinterface(Context c) {
            context = c;
        }

        @JavascriptInterface
        public void goBack() {
            finish();
        }


    }


    @Override
    public void showErr(String e) {

    }

    @Override
    public IForgotPasswordContract.Presenter createPresenter() {
        return new ForgotPasswordPresenter();
    }

    @Override
    public IForgotPasswordContract.View createView() {
        return this;
    }
}

